﻿using System.Collections.Generic;
using NUnit.Framework;

namespace ExtensionMethodExtravaganza.Tests
{
	[TestFixture]
	public class StringExtensionsTest
	{
		[Test]
		public void DefaultTest()
		{
			var s = "hello";
			var defaultValue = "default";
			Assert.AreEqual(s, s.Default(defaultValue));

			s = "";
			Assert.AreEqual(defaultValue, s.Default(defaultValue));

			s = null;
			Assert.AreEqual(defaultValue, s.Default(defaultValue));
		}

		[Test]
		public void DefaultNullOnlyTest()
		{
			var test = "hello";
			var defaultValue = "default";
			Assert.AreEqual(test, test.Default(defaultValue));

			test = "";
			Assert.AreEqual("", test.Default(defaultValue, true));
			Assert.AreEqual(defaultValue, test.Default(defaultValue, false));

			test = null;
			Assert.AreEqual(defaultValue, test.Default(defaultValue, true));
			Assert.AreEqual(defaultValue, test.Default(defaultValue, false));
		}

		[Test]
		public void RemoveEmptyElementsTest()
		{
			var list = new List<string> { "1", "", null, "2" };
			var smallList = new List<string>(list.RemoveEmptyElements());

			Assert.AreEqual(4, list.Count);
			Assert.AreEqual(2, smallList.Count);
			Assert.AreEqual("1", smallList[0]);
			Assert.AreEqual("2", smallList[1]);
		}

		[Test]
		public void FormatTest()
		{
			Assert.AreEqual("a.b.c", "{0}.{1}.{2}".Fmt("a", "b", "c"));
		}
	}
}
